package com.dayuanit.dy8.mall.springbootmall.controller;

import com.dayuanit.dy8.mall.springbootmall.dto.ResponseDTO;
import com.dayuanit.dy8.mall.springbootmall.service.CommonService;
import com.dayuanit.dy8.mall.springbootmall.vo.SettleInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class OrderController {

    @Autowired
    private CommonService commonService;

    @RequestMapping("/order/loadBuyCommon")
    public ResponseDTO loadBuyCommon(HttpServletRequest request, HttpSession session) {
        int commonId = (int)session.getAttribute("commoId");
        int buyNum = (int)session.getAttribute("buyNum");

        return ResponseDTO.success(commonService.loadBuyCommon(commonId, buyNum));
    }

    @RequestMapping("/order/settleCase1")
    public ResponseDTO settleCase1(String settleInfos) {
        System.out.println(settleInfos);
        return ResponseDTO.success();
    }

    @RequestMapping("/order/settleCase2")
    public ResponseDTO settleCase2(@RequestBody List<SettleInfoVo> settleInfos) {
        for (SettleInfoVo vo : settleInfos) {
            System.out.println(vo.getCartId() + "-" + vo.getCommoId() + "-" + vo.getBuyNum());
        }
        return ResponseDTO.success();
    }
}
